package cn.com.suiyi.shixingshengxian.welcome;

import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.widget.ImageView;

import butterknife.InjectView;
import cn.com.suiyi.shixingshengxian.R;
import cn.com.suiyi.shixingshengxian.base.BaseActivity;
import cn.com.suiyi.shixingshengxian.firstrun.FirstRunActivity;
import cn.com.suiyi.shixingshengxian.main.MainActivity;

/**
 * Created by Administrator on 2016/7/18.
 */
public class WelcomeActivity extends BaseActivity {
    private Handler handler = new Handler();
    @InjectView(R.id.imageview_welcome)
    ImageView imageviewWelcome;

    @Override
    public int getLayout() {
        return R.layout.activity_welcome;
    }


    @Override
    public void initView() {
        imageviewWelcome.setImageResource(R.mipmap.welcome);
    }


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                SharedPreferences sharedPreferences = getApplicationContext().getSharedPreferences("share", MODE_PRIVATE);
                boolean isFirstRun = sharedPreferences.getBoolean("isFirstRun", true);
                SharedPreferences.Editor editor = sharedPreferences.edit();
                if (isFirstRun) {
                    Log.d("debug", "第一次运行");
                    Intent intent = new Intent(WelcomeActivity.this, FirstRunActivity.class);
                    startActivity(intent);
                    editor.putBoolean("isFirstRun", false);
                    editor.commit();
                } else {
                    Log.d("debug", "不是第一次运行");
                    Intent intent=new Intent(WelcomeActivity.this, MainActivity.class);
                    startActivity(intent);
                }
                WelcomeActivity.this.finish();
            }
        }, 1000);
    }

    @Override
    protected void initData() {

    }
}
